package com.openingedu.mba.screen.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lurencun.android.support.widget.CommonAdapter;
import com.openingedu.mba.R;
import com.openingedu.mba.entity.PaperVO;

public class LocalLogicAdapter extends CommonAdapter<PaperVO>{

	private Context mContext;
	final Handler handler;
	
	public LocalLogicAdapter(Context context, Handler handler) {
		super(context);
		mContext = context;
		this.handler = handler;
	}

	@Override
	protected View createView(LayoutInflater inflater, final PaperVO data,
			int position, View convertView, ViewGroup parent) {
		LinearLayout itemLayout = (LinearLayout) inflater.inflate(R.layout.item_local_logic, null);
		// 试题名称
		TextView paperTitle = (TextView) itemLayout.findViewById(R.id.paper_title);
		TextView numTextView = (TextView) itemLayout.findViewById(R.id.question_num_tv);
		Button practiceBtn = (Button) itemLayout.findViewById(R.id.practice_btn);
		practiceBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Log.i("----", data.toString());
				Message msg = Message.obtain(handler, 0, data);
				Toast.makeText(mContext, "" + data.getPaperID(), Toast.LENGTH_LONG).show();
				handler.sendMessage(msg);
			}
		});
		paperTitle.setText(data.getPaperTitle());
		if (data.getPaperQuestionList()!=null) {
			numTextView.setText("" + data.getPaperQuestionList().size());
		}else {
			numTextView.setText("0");
		}
		return itemLayout;
	}

}
